<template>
  <div class="configuration-management">
    <el-card class="tabs-card">
      <el-tabs class="custom-tabs" v-model="activeName" tab-position="top">
<!--        <el-tab-pane label="安全分类" name="safetyClassification">-->
<!--          <el-card class="search-card" v-show="showSearch">-->
<!--            <div class="form-wrap">-->
<!--              <el-form @submit.native.prevent :model="queryParams" ref="queryForm" :inline="true" label-width="46px">-->
<!--                <el-form-item prop="searchValue">-->
<!--                  <el-input v-model="queryParams.searchValue" placeholder="请输入" clearable-->
<!--                            @keyup.enter.native="handleQuery"/>-->
<!--                </el-form-item>-->
<!--                <el-form-item>-->
<!--                  <el-date-picker-->
<!--                    v-model="dateRange"-->
<!--                    style="width: 240px"-->
<!--                    value-format="yyyy-MM-dd"-->
<!--                    type="daterange"-->
<!--                    range-separator="-"-->
<!--                    start-placeholder="开始日期"-->
<!--                    end-placeholder="结束日期"-->
<!--                  ></el-date-picker>-->
<!--                </el-form-item>-->
<!--              </el-form>-->
<!--              <div class="search-btn-group">-->
<!--                <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('search') }}</el-button>-->
<!--                <el-button class="button-ty" icon="el-icon-refresh" @click="resetQuery">{{ $t('reset') }}</el-button>-->
<!--              </div>-->
<!--            </div>-->
<!--          </el-card>-->

<!--          <el-card class="table-card" style="border-radius: 0px">-->
<!--            <el-row :gutter="10" style="margin-bottom: 16px">-->
<!--              <el-col :span="1.5">-->
<!--                <el-button type="success" icon="el-icon-plus" size="small" @click="handleAdd">新增</el-button>-->
<!--              </el-col>-->
<!--              <el-col :span="1.5">-->
<!--                <el-button type="warning" icon="el-icon-edit" size="small" :disabled="single" @click="handleUpdate">修改</el-button>-->
<!--              </el-col>-->
<!--              <el-col :span="1.5">-->
<!--                <el-button type="danger" icon="el-icon-delete" size="small" :disabled="multiple" @click="handleDelete">删除</el-button>-->
<!--              </el-col>-->
<!--              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />-->
<!--            </el-row>-->
<!--            <div class="data-table">-->
<!--              <el-table v-loading="loading" :data="tableData" :row-key="getRowKey"-->
<!--                        :border="false" @selection-change="handleSelectionChange" ref="multipleTable">-->
<!--                <el-table-column :reserve-selection="true" type="selection" width="55" align="center"/>-->
<!--                <el-table-column prop="id" label="ID" width="50" align="center"></el-table-column>-->
<!--                <el-table-column prop="majorCode" label="编码" align="center"></el-table-column>-->
<!--                <el-table-column prop="majorName" label="名称" align="center"></el-table-column>-->
<!--                <el-table-column prop="description" label="描述" align="center"></el-table-column>-->
<!--                <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width"-->
<!--                                 width="180">-->
<!--                  <template v-slot="scope">-->
<!--                    <el-button size="small" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">修改-->
<!--                    </el-button>-->
<!--                    <el-button size="small" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除-->
<!--                    </el-button>-->
<!--                  </template>-->
<!--                </el-table-column>-->
<!--              </el-table>-->

<!--              <pagination style="margin-bottom: 20px" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />-->
<!--            </div>-->
<!--          </el-card>-->
<!--        </el-tab-pane>-->
        <el-tab-pane label="产品分类" name="productClassification">
          <div class="card-container">
            <product-table/>
          </div>
        </el-tab-pane>
        <el-tab-pane label="视频列表" name="videoList">
          <div class="card-container">
            <video-table/>
          </div>
        </el-tab-pane>
<!--        <el-tab-pane label="安全事件" name="algorithmConfiguration">-->
<!--          <div class="card-container">-->
<!--            <algorithm-table/>-->
<!--          </div>-->
<!--        </el-tab-pane>-->
      </el-tabs>
    </el-card>

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog class="form-dialog" :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="编码" prop="majorCode">
          <el-input v-model="form.majorCode" placeholder="请输入安全分类编码" style="width: 400px" />
        </el-form-item>
        <el-form-item label="名称" prop="majorName">
          <el-input v-model="form.majorName" placeholder="请输入安全分类名称" style="width: 400px" />
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input v-model="form.description" type="textarea" placeholder="请输入安全分类描述" :autosize="{ minRows: 3, maxRows: 5 }" style="width: 400px"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-show="form.id">{{ $t('update') }}</el-button>
        <el-button type="primary" @click="submitForm" v-show="!form.id">{{ $t('add') }}</el-button>
        <el-button @click="cancel">{{ $t('cancel') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getSecurityCategoryList, removeSecurityCategory, detailSecurityCategory, addSecurityCategory, editSecurityCategory } from '@/api/private/configurationManagement';
import productTable from '@/views/components/configuration/productTable.vue';
import videoTable from '@/views/components/configuration/videoTable.vue';
import algorithmTable from '@/views/components/configuration/algorithmTable.vue';

export default {
  name: "ConfigurationManagement",
  components: {
    productTable,
    videoTable,
    algorithmTable
  },
  data() {
    return {
      activeName: 'productClassification',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      tableData: [],
      dateRange: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchValue: null,
        tenantId: "1",
      },
      // 总条数
      total: 0,
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {
      },
      rules: {
        majorCode: [{ required: true, message: "请输入安全分类编码", trigger: 'blur' }],
        majorName: [{ required: true, message: "请输入安全分类名称", trigger: 'blur' }],
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true;
      getSecurityCategoryList(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
        this.tableData = response.rows || [];
        this.total = response.total;
        this.loading = false;
      });
      this.loading = false;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    getRowKey: (row) => row.id ? row.id.toString() : Math.random().toString(36).substring(2),
    // 表单重置
    reset() {
      this.form = {
        tenantId: 1,
        id: undefined,
        majorCode: undefined,
        majorName: undefined,
        description: undefined,
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm('queryForm');
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加安全分类";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const dictId = row.id || this.ids;
      detailSecurityCategory(dictId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改安全分类";
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            editSecurityCategory(this.form).then((response) => {
              this.$modal.msgSuccess(this.$t('updateSuccess'));
              this.open = false;
              this.getList();
            });
          } else {
            addSecurityCategory(this.form).then((response) => {
              this.$modal.msgSuccess(this.$t('addSuccess'));
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const dictIds = row.id || this.ids;
      this.$modal
        .confirm(this.$t('system.dict.index.880996-11', [dictIds]))
        .then(function () {
          return removeSecurityCategory(dictIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess(this.$t('delSuccess'));
          this.$refs.multipleTable.clearSelection();
        })
        .catch(() => {});
    },
  }
}
</script>

<style lang="scss" scoped>
.configuration-management {
  z-index: 1;
  min-height: calc(100vh - (72 / 1080 * 100vh));
  background: rgba(0,11,61,0.8);
  padding: 10px;

  ::v-deep .el-form-item__label {
    color: #ffffff;
  }
}

.tabs-card {
  border-radius: 8px;
  width: 100%;
  background: rgba(0,11,61,0.8);
  color: #fff;
  border-width: #{px2vw(1)};
  border-style: solid;

  // 2. 渐变边框背景（核心样式，颜色部分无需转换）
  border-image: linear-gradient(
      180deg,
      rgba(22, 93, 255, 0),
      rgba(22, 93, 255, 0.59),
      rgba(22, 93, 255, 1)
  ) 1 1;
}

.search-card {
  background: rgba(0,11,61,0.8);
  color: #fff;
  border: none;
  margin-bottom: 15px;
  padding: 3px 0;

  .form-wrap {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-end;
    //margin-bottom: -22.5px;

    .search-btn-group {
      display: flex;
      flex-direction: row;
      margin-bottom: 22px;
    }

    ::v-deep .el-input__inner {
      background: rgba(255, 255, 255, 0.1);
      border-color: rgba(22, 93, 255, 0.5);
      color: #fff; /* 文字颜色 */
    }
    ::v-deep .el-range-editor--medium .el-range-input {
      background: none;
      color: #fff; /* 文字颜色 */
    }
  }
}
.button-ty {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(22, 93, 255, 0.5);
  color: #fff; /* 文字颜色 */
}

::v-deep .top-right-btn .custom-button[data-v-38ed449c] {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(22, 93, 255, 0.5);
  color: #fff; /* 文字颜色 */
}

.table-card {
  background: rgba(0,11,61,0.8);
  border: none;
}

.data-table {
  ::v-deep .el-table {
    border: none !important;
  }

  /* 2. 表头背景（列标题区域） */
  ::v-deep .el-table tr {
    background: rgba(22,93,255);
  }
  /* 2. 表头字体大小（列标题区域） */
  ::v-deep .el-table th.el-table__cell>.cell {
    //font-size: px2font(16);
    //border-right: none !important; /* 移除单元格右侧边框 */
    //border-left: none !important; /* 移除单元格左侧边框（通常默认无，但保险起见） */
  }

  /* 3. 表格体背景（数据行区域） */
  /* 3.1 普通行背景 */
  ::v-deep .el-table__body-wrapper,
  ::v-deep .el-table__row {
    background: rgba(0,11,61,0.79) !important; /* 普通行背景（示例：白色） */
  }
  /* 3.1 普通行字体大小 */
  ::v-deep .el-table td.el-table__cell div {
    //font-size: px2font(14);
  }
  /* 表格体单元格背景（确保与行背景一致） */
  ::v-deep .el-table__cell {
    //background-color: inherit !important; /* 继承行背景 */
    background: rgba(0,11,61,0.79) !important; /* 表格体文字颜色（可选） */
    border-right: none !important; /* 移除单元格右侧边框 */
    border-left: none !important; /* 移除单元格左侧边框（通常默认无，但保险起见） */
    border: 1px solid rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.9);
  }

  /* 4. 行 hover 状态背景（鼠标悬停时） */
  ::v-deep .el-table__row:hover {
    background: rgba(22,93,255,0.4) !important; /* hover 背景（示例：淡蓝） */
  }

  /* 5. 表格边框颜色（可选：与背景色协调） */
  ::v-deep .el-table__border,
  ::v-deep .el-table-cell {
    background: rgba(0,11,61,0.79) !important; /* 边框颜色（示例：浅灰） */
  }

  ::v-deep .el-table--border::after, .el-table--group::after {
    width: 0 !important;
  }

  ::v-deep .el-table::before {
    height: 0 !important;
  }
  ::v-deep .el-button--text {
    color: #ffffff;
  }

  /* 1. 分页组件整体文字颜色（基础设置） */
  ::v-deep .el-pagination {
    color: #ffffff !important; /* 默认文字颜色（示例：深灰色） */
  }

  ::v-deep input.el-input__inner {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(22, 93, 255, 0.5);
    color: #ffffff;
  }

  ::v-deep button.btn-prev {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(22, 93, 255, 0.5);
    color: #ffffff;
  }

  ::v-deep button.btn-next {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(22, 93, 255, 0.5);
    color: #ffffff;
  }

  /* 2. 页码按钮文字颜色 */
  ::v-deep .el-pager li {
    color: #ffffff !important; /* 普通页码文字 */
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(22, 93, 255, 0.5) !important;
  }

  /* 3. 当前选中页码的文字颜色 */
  ::v-deep .el-pager li.active {
    background-color: #409EFF !important;
    color: #ffffff !important; /* 选中页码文字（通常与背景色对比） */
  }

  /* 4. 上一页/下一页按钮文字颜色 */
  ::v-deep .el-pagination__prev,
  ::v-deep .el-pagination__next {
    color: #ffffff !important; /* 箭头按钮文字 */
  }

  /* 5. 禁用状态（如第一页的"上一页"）的文字颜色 */
  ::v-deep .el-pagination__prev.is-disabled,
  ::v-deep .el-pagination__next.is-disabled {
    color: #ffffff !important; /* 禁用状态文字（示例：浅灰色） */
  }

  /* 6. 总条数/跳转文本的颜色（如"共 100 条"） */
  ::v-deep .el-pagination__total,
  ::v-deep .el-pagination__jump {
    color: #ffffff !important; /* 说明文字颜色 */
  }

  ::v-deep .pagination-container {
    background: none;
    margin-top: px2vh(10);
    margin-bottom: px2vh(20);
  }

  ::v-deep .el-input--medium .el-input__inner {
    height: 28px;
  }
}

.custom-tabs {
  .basic-span {
    margin-top: 16px;
  }

  ::v-deep .el-card__body {
    padding: 20px 0 0 0;
  }

  ::v-deep .el-tabs__active-bar {
    background-color: transparent;
  }

  ::v-deep.el-tabs__nav {
    margin-bottom: 12px;
  }

  ::v-deep .el-tabs__item {
    padding: 0px 25px !important;
    box-sizing: border-box;
    display: inline-block;
    list-style: none;
    font-size: 14px;
    font-weight: 500;
    color: #ffffff;
    position: relative;
  }

  ::v-deep .el-tabs__item.is-active {
    color: #fff;
    background-color: #486ff2;
    border-radius: 4px;
    height: 32px;
    line-height: 34px;
  }
}
::v-deep .el-dialog {
  margin-top: 8vh !important;
  background: rgba(0,11,61);
}
.form-dialog {
  ::v-deep .el-input__inner {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(22, 93, 255, 0.5);
    color: #fff; /* 文字颜色 */
  }
  ::v-deep .el-textarea__inner {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(22, 93, 255, 0.5);
    color: #ffffff;
  }
  ::v-deep .el-dialog__title {
    color: #ffffff;
  }
  ::v-deep .el-dialog__headerbtn .el-dialog__close {
    color: #ffffff;
  }
  ::v-deep .el-form-item__label {
    color: #ffffff;
  }
}
</style>
